﻿import tv.zarate.Utils.Delegate
import mx.events.EventDispatcher;

/**
 *
 * @author	Hector Centeno
 * @version	0.2
 **/
class com.neshumah.XML.XmlManager   {
	var XmlObject:Array;
	var XmlUrl:Array;
	
	//dispatcher vars
	var addEventListener:Function;
	var removeEventListener:Function;
	var dispatchEvent:Function
	
	function XmlManager(){
		this.XmlObject=new Array();
		this.XmlUrl= new Array();
		EventDispatcher.initialize(this);
	}
	
	function loader(urll:String):Void{
		var lXml:XML;
		var n:Number;
		var viejo:Boolean=true;
		for(n=0; n<this.XmlUrl.length; n++){
			if(urll==this.XmlUrl[n]){
				viejo=false;
				manageLoad(true,this.XmlObject[n]);
			}
		}
		
		if(viejo){
			lXml=new XML();
			lXml.ignoreWhite=true;
			lXml.onLoad=Delegate.create(this,manageLoad,lXml);
			lXml.load(urll);
			this.XmlObject.push(lXml);
			this.XmlUrl.push(urll);
			
		}
	}
	
	
	private function manageLoad(success:Boolean,xmlData:XML){
		dispatchEvent({type:'onLoad', target:this, data:xmlData});
		}
}